<?php
function doiso($so)
{
//var  $Chu , $solop , $so1 , $tg ;
    if ($so == 0 || $so == "")
    { return "-" ; }

    if ($so < 0)
    {
        $Chu = "(&#194;m) " ;
        $so = 0 - $so ;
    }
//ReDim term(10) , lop(6) , tlop(6)

    $term["1"] = " m&#7897;t" ;
    $term["2"] = " hai";
    $term["3"] = " ba";
    $term["4"] = " b&#7889;n";
    $term["5"] = " n&#259;m";
    $term["6"] = " s&#225;u";
    $term["7"] = " b&#7843;y";
    $term["8"] = " t&#225;m";
    $term["9"] = " ch&#237;n";

    $tlop["1"] = "" ;
    $tlop["2"] = " ng&#224;n";
    $tlop["3"] = " tri&#7879;u";
    $tlop["4"] = " t&#7927;";
    $tlop["5"] = " ng&#224;n t&#7927;";
    $tlop["6"] = " tri&#7879;u t&#7927;";

    $so1 = $so ;
    $solop = 1;
    while ($so1 > 0)
    {
        $tg = $so1 ;
        $so1 =  intval($so1 / 1000); // int coi lai

        $lop[$solop] = $tg - $so1 * 1000;
        $solop = $solop + 1 ;
    }
    $i = $solop - 1 ;
// $Chu = ""
    while ($i > 0 )
    {
        $so1 = $lop[$i] ;
        if ($so1 > 0 )
        {
            $hangtram = intval($so1 / 100 ) ;
            $hangchuc =  intval(($so1 - $hangtram * 100)/ 10 );
            $hangdonvi = $so1 - $hangtram * 100 - $hangchuc * 10 ;
            if ($hangtram > 0 )
            {	//Chu $so hang tram c ngha $so1>=100
                $Chu = $Chu . $term[$hangtram] . " tr&#259;m" ;
            }
//Xet chu $so hang chuc
            if ( $hangchuc > 1 )
            {
                $Chu = $Chu . $term[$hangchuc] . " m&#432;&#417;i" ;

            }elseif ($hangchuc == 1 )
            {
                $Chu = $Chu . " m&#432;&#7901;i" ;
            }elseif ($hangchuc == 0 && $so1 > 100 && $hangdonvi != 0 )
            {
                $Chu = $Chu . " l&#7867;" ;
            }
// Xet ch s- hng n v"
            if ($hangdonvi != 5 && $hangdonvi != 0 && $hangdonvi != 1 )
            {
                $Chu = $Chu . $term[$hangdonvi] ;
            }
            elseif ($hangdonvi == 5 && $hangchuc != 0 )
            {
                $Chu = $Chu . " l&#259;m " ;
            }
            elseif ($hangdonvi == 5 && $hangchuc == 0 )
            { $Chu = $Chu . " n&#259;m " ;}
            elseif ($hangdonvi == 1 && $hangchuc > 1 )
            {
                $Chu = $Chu . " m&#7889;t" ;
            }
            else
            { $Chu = $Chu . $term[$hangdonvi] ;
            }

            $Chu = $Chu . $tlop[$i] ;
        }
// Xet lop ke tiep
        $i = $i - 1 ;
    } // Loop
    $Chu = trim($Chu);

    if ($Chu != "" )
    {
        $Chu = strtoupper(substr($Chu,0,1)) . substr($Chu,1,strlen($Chu) - 1) . " &#273;&#7891;ng ch&#7861;n" ;
    }
    return $Chu ;

}?>